package top.vanchor.flexible.config;

import io.minio.MinioClient;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import top.vanchor.flexible.config.consts.OssConst;

import javax.annotation.PostConstruct;

@Data
@Configuration
@ConfigurationProperties(prefix = "minio")
public class MinioConfig {
    private String endpoint;
    private String accessKey;
    private String secretKey;
    private String bucketName;  // 增加 bucketName 属性

    /**
     * 注入minio客户端
     *
     * @return MinioClient
     */
    @Bean
    public MinioClient minioClient() {
        return MinioClient.builder()
                .endpoint(endpoint)
                .credentials(accessKey, secretKey)
                .build();
    }

    /**
     * 在构造完成后设置静态常量
     */
    @PostConstruct
    public void initOssConst() {
        MinioConfig.END_POINT = this.endpoint;
        MinioConfig.BUCKET_NAME = this.bucketName;
    }

    /**
     * OSS-bucket名称
     */
    public static String BUCKET_NAME;

    /**
     * OSS-bucket路径
     */
    public static String END_POINT;

}
